#include "TCBlobTrackToStringConverter.h"

using namespace plv;
using namespace plvblobtracker;

#include <opencv/cv.h>

TCBlobTrackToStringConverter::TCBlobTrackToStringConverter()
{
	m_inputTracks = createInputPin< QList<BlobTrack> >( "input tracks", this );
	m_outputPin = createOutputPin< QString >( "output string", this );
}

TCBlobTrackToStringConverter::~TCBlobTrackToStringConverter()
{
}

bool TCBlobTrackToStringConverter::process()
{
	QList<BlobTrack> tracks = m_inputTracks->get();
	QString out = QString("FRAME:%1#").arg(this->getProcessingSerial());
	
	foreach(BlobTrack bt, tracks)
	{
		Blob b			= bt.getLastMeasurement();
		cv::Point cog	= b.getCenterOfGravity();
		cv::Rect rect	= b.getBoundingRect();

		// Create a string for this blob
		QString blobstr =
			QString("BEGIN_BLOBTRACK#ID:%1#X:%2#Y:%3#WIDTH:%4#HEIGHT:%5#")
			.arg(bt.getId())
			.arg(cog.x)
			.arg(cog.y)
			.arg(rect.width)
			.arg(rect.height);

		out.append(blobstr);
	}

	// End with new line
	out.append("\n");

	// To output pin
	m_outputPin->put(out);
	
	return true;
}